package alogrithm;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/10/31 21:37
 */
public class FindWords {

    public String[] findWords(String[] words) {
        String idxs = "12210111011122000010020202";
        List<String> tmp = new ArrayList<>();
        for (String word : words) {
            int idx = idxs.charAt(Character.toLowerCase(word.charAt(0)) - 'a');
            boolean isValid = true;
            for (int i = 1; i < word.length(); ++i) {
                if (idxs.charAt(Character.toLowerCase(word.charAt(i)) - 'a') != idx) {
                    isValid = false;
                    break;
                }
            }
            if (isValid) {
                tmp.add(word);
            }
        }

        String[] res = new String[tmp.size()];
        for (int i = 0; i < tmp.size(); ++i) {
            res[i] = tmp.get(i);
        }
        return res;
    }
}
